package com.atguigu.lease.common.mybatisplus;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class MybatisMetaObjectHandler implements MetaObjectHandler {

    // 插入数据的时候
    @Override
    public void insertFill(MetaObject metaObject) {
        /**
         * 1. metaObject 获取类的信息
         * 2. 属性名 要给哪个属性复制
         * 3. 属性类型
         * 4. 具体的值
         */
        this.strictInsertFill(metaObject, "createTime", Date.class, new Date());

    }

    // 更新数据的时候
    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject, "updateTime", Date.class, new Date());
    }
}
